package com.cjd.common.utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

/**
 * @Author chenjidong
 * @email 374122600@qq.com
 * created 2019/11/12
 * description 系统自带分享
 */
public class SystemShareUtil {

    /**
     * 分享文本
     *
     * @param context 上下文
     * @param text    内容
     */
    public static void share(Context context, String text) {
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, text);
        shareIntent = Intent.createChooser(shareIntent, "请选择分享的应用");
        context.startActivity(shareIntent);
    }

    /**
     * 分享 资源文件
     *
     * @param context 上下文
     * @param resId   资源id
     */
    public static void share(Context context, int resId) {
        Uri uri = Uri.parse("android:resource://" + context.getPackageName() + "/" + resId);
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("image/*");
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent = Intent.createChooser(shareIntent, "请选择分享的应用");
        context.startActivity(shareIntent);
    }
}
